#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
int main(int argc,char* argv[])
{
	if(argc < 3)
	{
		printf("incorrect parameter\n");
		return 1;
	}
	int client_fd = socket(AF_INET,SOCK_STREAM,0);
	struct sockaddr_in client_attr;
	memset(&client_attr,0,sizeof(client_attr));
	client_attr.sin_family = AF_INET;
	// 主机字节序转换成网络字节序
	client_attr.sin_port = htons((short)atoi(argv[2]));
	inet_pton(AF_INET,argv[1],&client_attr.sin_addr.s_addr);
	// client_attr.sin_addr.s_addr = 
	if(-1 == connect(client_fd,(struct sockaddr*)&client_attr,sizeof(client_attr)))
	{
		perror("connect ");
		return 1;
	}
	char res[512] = {'\0'};
	while(1)
	{
		printf(">");
		scanf("%s",res);
		write(client_fd,res,sizeof(res));
		read(client_fd,res,sizeof(res));
		printf("%s",res);
	}
	close(client_fd);
	return 0;
}
